﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_select_hanghh : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        thuvien tv;
        DataTable tb;

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_select_hanghh).Assembly);
                radio_nhomchu.Text = rm.GetString("nhomchu", culture);
                radio_nhomhang.Text = rm.GetString("nhomhang", culture);
                radio_hanghoa.Text = rm.GetString("hanghoa", culture);
                bton_thoat.Text = rm.GetString("thoat", culture);
                this.col_ma.Caption = rm.GetString("ma", culture);
                this.col_ten.Caption = rm.GetString("nhomchu", culture);
                this.col_manh.Caption = rm.GetString("ma", culture);
                this.col_tennh.Caption= rm.GetString("nhomhang", culture);
                this.col_mahh.Caption= rm.GetString("ma", culture);
                this.col_tenhh.Caption= rm.GetString("mon", culture);
                            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        #region cac ham va phuong thuc

        private DataTable f_dsnhomchu()
        {
            tv = new thuvien();
            string[] s = new string[] { "@flag", "@choose" };
            object[] o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mh_select_hanghh ", s, o);
            return tb;
        }
        private DataTable f_dsnhomhang()
        {
            tv = new thuvien();
            string[] s = new string[] { "@flag", "@choose" };
            object[] o = new object[] { 1, 2 };
            tb = tv.SP_SelectDataTable("sp_mh_select_hanghh ", s, o);
            return tb;
        }
        private DataTable f_dshanghoa()
        {

            tv = new thuvien();
            string[] s = new string[] { "@flag", "@choose" };
            object[] o = new object[] { 1, 3 };
            tb = tv.SP_SelectDataTable("sp_mh_select_hanghh ", s, o);
            return tb;
        }
        private void f_showdataongrid()
        {

          tb = null;
            if (radio_nhomchu.Checked == true)
            {
                luoi_hh.MainView = grid_nhomchu;
                tb=f_dsnhomchu ();
                
            }
            else if (radio_nhomhang.Checked == true)
            {
                luoi_hh.MainView = grid_nhomhang ;
                tb = f_dsnhomhang();
             
            }
                else if (radio_hanghoa.Checked == true)
                {
                    luoi_hh.MainView = grid_hanghoa;
                    tb = f_dshanghoa();
          
                }
           luoi_hh.DataSource = tb;
        }
     public mh_select_hanghh()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }

        #endregion

        #region cac su kien

        private void bton_thoat_Click(object sender, EventArgs e)
        {
          

            this.Close();
        }

        private void radio_nhomchu_CheckedChanged(object sender, EventArgs e)
        {
            f_showdataongrid();
        }
        private void radio_nhomhang_CheckedChanged(object sender, EventArgs e)
        {
            f_showdataongrid();
        }

      

        private void mh_select_hanghh_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";

            SetLanguage_banhang(str_lang);
            f_showdataongrid();
            CancelButton = bton_thoat;
        }


        #endregion

        //private void grid_nhomchu_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        //{
        //    //int chiso = e.FocusedRowHandle;
        //    //string _chiso = Convert.ToString(chiso);
        //    //GridColumn col = grid_nhomchu.FocusedColumn;
        //    //string manhomchu = grid_nhomchu.GetRowCellDisplayText(chiso, col) + "";

        // //   DevExpress.XtraGrid.Views.Grid.GridView grid = new GridView();
        //    GridView grid = (GridView)sender;
        //    Variable.str_manhomchu = grid.GetRowCellValue(grid_nhomchu.FocusedRowHandle, col_ma).ToString();
        //    Variable.int_trangthai = 0;
        //}

        public int itrangthai = 0;
        public string sMaHang = "";
        private void grid_nhomchu_DoubleClick(object sender, EventArgs e)
        {
            GridView grid = (GridView)sender;
            //Variable.str_manhomchu = grid.GetRowCellValue(grid_nhomchu.FocusedRowHandle, col_ma)+"";
            sMaHang = grid.GetRowCellValue(grid_nhomchu.FocusedRowHandle, col_ma)+"";
            //Variable.int_trangthai = 0;
            itrangthai = 0;
            this.Dispose();
            
        }

  
        private void grid_nhomhang_DoubleClick(object sender, EventArgs e)
        {
            GridView grid = (GridView)sender;
            //Variable.str_manhomhang = grid.GetRowCellValue(grid_nhomhang.FocusedRowHandle, col_ma)+"";
            //Variable.int_trangthai = 1;
            sMaHang = grid.GetRowCellValue(grid_nhomhang.FocusedRowHandle, col_ma) + "";
            itrangthai = 1;
            this.Dispose();
        }

        private void grid_hanghoa_DoubleClick(object sender, EventArgs e)
        {
            GridView grid = (GridView)sender;
            //Variable.str_mahh = grid.GetRowCellValue(grid_hanghoa.FocusedRowHandle, col_ma) + "";
            //Variable.int_trangthai = 2;
            sMaHang = grid.GetRowCellValue(grid_hanghoa.FocusedRowHandle, col_ma) + "";
            itrangthai = 2;
            this.Dispose();
        }

        private void luoi_hh_Click(object sender, EventArgs e)
        {

        }
        
      
    }
}